package com.baicaoyuan.web.repository;


import com.baicaoyuan.web.model.RequirementDO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 功能描述：需求发布
 *
 * @author 罗富祥
 * 创建时间： 2018/1/4
 * 版权：
 */
@Repository
public interface RequirementRepository extends JpaRepository<RequirementDO, Long> {

    @Query(value = "select * from t_requirement where status != 9 and user_telephone like ?1 and category like ?2 order by create_time desc Limit ?3,?4", nativeQuery = true)
    List<RequirementDO> getRequirements(String telephone, String category, Integer page, Integer size);


    @Transactional
    @Modifying
    @Query(value = "update t_requirement set status = ?2 where id = ?1", nativeQuery = true)
    Integer updateStatus(Long id, String status);

    Integer countAllByStatusIsNotAndTelephoneLikeAndCategory(String status, String telephone, String category);

    List<RequirementDO> findByUserFkAndCategory(Long userId, String category, Pageable pageable);

}
